package util;

import enums.BaseRespCodeEnum;
import org.springframework.http.HttpStatus;


/**
 * @author xiongyx
 * @date 2020/6/3
 */
public class WebExceptionUtil {

    public static BaseRespCodeEnum processCodeByHttpStatus(HttpStatus httpStatus) {
        BaseRespCodeEnum code;
        switch (httpStatus) {
            case OK:
                code = BaseRespCodeEnum.SUC;
                break;
            case BAD_REQUEST:
                code = BaseRespCodeEnum.PARAMS_ILLEGAL;
                break;
            case SERVICE_UNAVAILABLE:
                code = BaseRespCodeEnum.SERVER_ERROR;
                break;
            case TOO_MANY_REQUESTS:
                code = BaseRespCodeEnum.REQUEST_BLOCKED;
                break;
            case NOT_FOUND:
                code = BaseRespCodeEnum.NOT_FOUND;
                break;
            default:
                code = BaseRespCodeEnum.SERVER_ERROR;
        }
        return code;
    }
}
